package myservice.android.utilities;

import android.text.Editable;
import android.text.TextWatcher;

/**
 * Listener for all EditText views that sets the activity as unsaved when the text is modified.
 */
public class NumberPickerMonitor implements TextWatcher {
	
	private NumberPicker picker;
	
	public NumberPickerMonitor(NumberPicker picker) {
		this.picker = picker;
	}

	@Override
	public void afterTextChanged(Editable s) {
		
		try {
			int newValue = Integer.parseInt(s.toString());
			if (newValue>=0 && newValue<=picker.maxValue) {
				picker.selected = newValue;
			}
		} catch (Exception e) {
			return;
		}			
		
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,	int after) { }	

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) { }	

}
